package cn.itcast.crm.service.impl.base;

import java.util.List;

















import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.crm.dao.base.ICustomerDAO;
import cn.itcast.crm.domain.Customer;
import cn.itcast.crm.service.base.ICustomerService;
@Service
@Transactional
public class CustomerServiceImpl implements ICustomerService {
	//注入dao
	@Autowired
	private ICustomerDAO customerDao;

	@Override
	//查询已关联的客户
	public List<Customer> findHasAssociationCustomer(String fixedAreaId) {
		
		return customerDao.findByFixedAreaId(fixedAreaId);
	}

	@Override
	//查询未关联的数据
	public List<Customer> findNoAssociationCustomer() {
		
		return customerDao.findByFixedAreaIdIsNull();
	}

	@Override
	//关联客户到定区的操作
	public void ssociationCustomersToFixedArea(String customerIdStr,
			String fixedAreaId) {
	//解除关联
		customerDao.clearFixedAreaId(fixedAreaId);
		  //切割字符串
		if("null".equals(customerIdStr)){
			return;
		}
		String[] strings = customerIdStr.split(",");
		for (String str : strings) {
			 Integer id = Integer.parseInt(str);
			
			customerDao.updateFixedAreaId(fixedAreaId,id);
		}
		
	}

	@Override
	public void regist(Customer customer) {
		customerDao.save(customer);
		
	}

	@Override
	public Customer findTelephone(String telephone) {
		
		return customerDao.findByTelephone(telephone);
	}

	@Override
	public void updatetype(String telephone) {
		customerDao.updatetype(telephone);
		
	}

	@Override
	public Customer findTelephoneAndpassword(String telephone, String password) {
	
		return customerDao.findByTelephoneAndPassword(telephone,password);
	}

	@Override
	public String findFixedAreaIdByAddress(String address) {
	
		return customerDao.findFixedAreaIdByAddress(address);
	}


	

}
